// pages/resources/resources.js
//获取应用实例
var app = getApp();
//引用
var fileData = require('../../utils/data.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner_url: [],
    interval: 3000,
    duration: 1000,
    vertical: false,
    indicatordots: true,
    autoplay: true,
    current: 1,
    indicatored: '#F08631',
    indicator: '#fff',
    navTopItems: fileData.getIndexNavData(),
    curNavId: 1,
    curIndex: 0,
    userInfo: '',
    colors: ["red", "orange", "yellow", "green", "purple"],
    focus: '', 
    advert_url: '',
    imgadvert_url: [],
    typelist: [
      { icon: 'icon-gengduo1', name: '更多', color: '', url: '../../pages/moreresource/moreresource' }
    ],
    loadSuccess: false
  },
  onSlideChangeEnd: function (e) {
    var that = this;
    that.setData({
      current: e.detail.current + 1
    })
  },  
  bingfocusFunc: function (e) {
    this.setData({
      focus: 'focus'
    })
  },
  bingblurFunc: function (e) {
    this.setData({
      focus: ''
    })
  },
  switchTap: function (e) {
    var url;
    var data = this.data.typelist[e.currentTarget.dataset.index];
    if(data.url){
      url=data.url;
    }else{
      url = '../../pages/healthCareSeach/healthCareSeach';
    }
    wx.navigateTo({
      url: url + "?item=" + JSON.stringify(data)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    
    fileData.getAdvertData.apply(this, ['3', 'advert_url']);
    fileData.getBannerData.apply(this, ['3', 'top', 0, 'banner_url']);
    fileData.getBannerData.apply(this, ['3', 'top', 1, 'imgadvert_url']);
  },
  enterDesk: function () {
    wx.navigateTo({
      url: '/pages/infoDesk/infoDesk?index=3',
    })
  },
  getLatelyUse:function(){
    var that=this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGyIndustryResource/toIndustryResourcesPage', //仅为示例，并非真实的接口地址
      data: {
        userId: this.data.userInfo.id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          loadSuccess: true
        })
        if(res.data.success){
          var arr = res.data.data.remoteList;
          arr.push({ icon: 'icon-gengduo1', name: '更多', color: '', url: '../../pages/moreresource/moreresource' });
          that.setData({
            typelist: arr
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      loadSuccess: false
    })
    wx.showLoading({})
    this.getLatelyUse();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})